<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>事件绑定</title>
    <style>
      .box{
        width: 200px;
        height: 100px;
        background: #aef;
        margin-bottom: 20px;
      }
      body{
        height: 2000px;
      }
    </style>
  </head>
  <body>
    <div id="root"></div>
    <script src="./js/react.development.js"></script>
    <script src="./js/react-dom.development.js"></script>
    <script src="./js/babel.min.js"></script>

    <script type="text/babel">
      let obj = {
        test: function(){
          alert('为难当前，唯有责任');
        }
      };

      //声明一个函数  返回一个函数
      function run(){
        return () => {
          alert('run run run');
        }
      }
      let tmp = run()
      //创建虚拟 DOM 对象
      let vdom = <div>
          <h2>事件绑定</h2>
          {/*简单函数*/}
          <div onClick={() => {
            alert('你点击了我')
          }} className="box"></div>
          {/* 对象方法 */}
          <div onClick={obj.test} className="box"></div>
          {/* 函数调用 */}
          <div onClick={tmp} className="box"></div>

          <h2>事件源的获取</h2>
          <div className="box" onClick={function(e){
            // console.log(e.target);
            e.target.style.background = '#a45';
          }}></div>

          <h2>取消默认行为</h2>
          <a onClick={(e) => {
            console.log(e);
            //阻止默认行为
            e.preventDefault()
          }} href="http://www.baidu.com">百度</a>

          <h2>change 事件</h2>
          <input type="text" onChange={() => {
            console.log('内容改变了啊~~');
          }} />
        </div>;

      //渲染
      ReactDOM.render(vdom, document.querySelector('#root'))
    </script>
</body>
</html>
